<?php
namespace app\restaurant\model;

use app\BaseModel;
use think\facade\Db;

class CouponLimit extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_restaurant_coupon_limit';



    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:04
     * @功能说明:添加
     */
    public function couponAdd($data,$type,$uniacid,$coupon_id){


        $this->where(['type'=>$type,'coupon_id'=>$coupon_id])->delete();


        foreach ($data as $k=>$v){

            $data[$k]['uniacid'] = $uniacid;

            $data[$k]['type']    = $type;

            $data[$k]['coupon_id'] = $coupon_id;

            $data[$k]['is_record'] = 0;
        }
        $res = $this->saveAll($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-10-20 18:17
     * @功能说明:领取记录添加
     */
    public function indexCouponAdd($data,$coupon_id){

        foreach ($data as $k=>$v){

            $data[$k]['coupon_id'] = $coupon_id;

            $data[$k]['is_record'] = 1;
        }
        $res = $this->saveAll($data);

        return $res;

    }

    /**
     * @param $type
     * @param $dis
     * @功能说明:
     * @author chenniang
     * @DataTime: 2020-10-10 17:22
     */
    public function getDataSelect($type,$dis){

        switch ($type){

            case 1:
                $table = 'longbing_card_restaurant_cate b';
                break;
            case 2:
                $table = 'longbing_card_restaurant_goods b';
                break;
            case 3:
                $table = 'longbing_card_restaurant_store b';
                break;

        }

        $data = $this->alias('a')
                ->join($table,'a.obj_id = b.id')
                ->where($dis)
                ->field('b.id,b.title')
                ->select()
                ->toArray();

        return $data;

    }



}